clear all
set more off
set matsize 10000
tempfile ubigeo temp

local controls schooling male rural native married head 

use mergedp, clear

egen voted_bn = rowmax(voted_blank voted_null)
recode voted_blank voted_null voted_bn (. = 0) if voted == 0

** LABELS
label var todoAT "Violence Exposure"
label var todoA "Violence Exposure - Army"
label var todoT "Violence Exposure - Terrorist"

******* Results
drop if vote_matter == .
local lista vote_matter voted voted_blank voted_null voted_bn voted_bn partN dem_works dem_matters1 gov_demo1 gov_auto1

gen depnac1993 = int(provnac1993/100)
gen dep1993 = int(prov1993/100)

gen migration_dist = ubigeonac1993 != ubigeo1993 
gen migration_prov = provnac1993 != prov1993
gen migration_dep = depnac1993 != dep1993

gen dist_prov = migration_dist == 1 & migration_prov == 0
gen dist_dep = migration_dist == 1 & migration_dep == 0

replace migration_dist = migration_dist 
replace migration_prov = migration_prov 
replace migration_dep = migration_dep 

reghdfe migration_dist todoAT `controls', abs(i.age i.year i.provid#c.trend) vce(cluster ubigeonac1993) keepsin
est store mdist_none

reghdfe migration_dist todoAT `controls' if dist_prov == 0 , abs(i.age i.year i.provid#c.trend) vce(cluster ubigeonac1993) keepsin
est store mprov_resnac

reghdfe migration_dist todoAT `controls' if dist_dep == 0, abs(i.age i.year i.provid#c.trend) vce(cluster ubigeonac1993) keepsin
est store mdep_resnac

reghdfe migration_dist todoA todoT `controls', abs(i.age i.year i.provid#c.trend) vce(cluster ubigeonac1993) keepsin
est store at_dist

reghdfe migration_dist todoA todoT `controls' if dist_prov == 0 , abs(i.age i.year i.provid#c.trend) vce(cluster ubigeonac1993) keepsin
est store at_prov

reghdfe migration_dist todoA todoT `controls' if dist_dep == 0, abs(i.age i.year i.provid#c.trend) vce(cluster ubigeonac1993) keepsin
est store at_dep

noisily estout m* ///
using Table_A1_0.tex, style(tex) c(b(fmt(2) star) se(par fmt(2))) ///
	label collabels(, none) eqlabels(none) mlabels(, none) varlabel(_cons " $ Control $ ") starlevel(* .1 ** .05 *** .01) ///
	keep(todoAT) ///
	order(todoAT) ///
	stats(r2 N N_clust, fmt(%9.2f %9.0g) labels(`"$ R ^{2}$"' "Observations" "Clusters")) replace 

noisily estout at_* ///
using Table_A1_0_at.tex, style(tex) c(b(fmt(2) star) se(par fmt(2))) ///
	label collabels(, none) eqlabels(none) mlabels(, none) varlabel(_cons " $ Control $ ") starlevel(* .1 ** .05 *** .01) ///
	keep(todoA todoT) ///
	order(todoA todoT) ///
	stats(r2 N N_clust, fmt(%9.2f %9.0g) labels(`"$ R ^{2}$"' "Observations" "Clusters")) replace 

	
texdoc init Table_A1.tex, replace
tex \begin{table}[h]
tex \caption{Impact of armed conflict on probability migration}
tex \label{tab:table2_review}
tex \begin{center}
tex \resizebox{12cm}{!}{
tex \begin{tabular}{lccc} \hline \hline
tex \\
tex & Moved & Moved & Moved \\
tex & District & District & District \\
tex &  & and Province & and Region \\
tex & (0/1) & (0/1) & (0/1) \\
tex & (1) & (2) & (3) \\
tex \\
tex \hline
tex \multicolumn{4}{c}{\textbf{Overall Exposure}} \\
tex \input{Table_A1_0.tex}
tex \\
tex \multicolumn{4}{c}{\textbf{Heterogeneous Exposure}} \\
tex \input{Table_A1_0_at.tex}
tex \\
tex Dep. Var. Average & 0.51 & 0.44 & 0.36 \\
tex \hline
tex \end{tabular}}
tex \end{center}
tex \end{table}
